home *** CD-ROM | disk | FTP | other *** search
- Path: Ra.MsState.Edu!mhp1
- From: mhp1@Ra.MsState.Edu (Michael H Price II)
- Newsgroups: comp.lang.c
- Subject: Re: array of struct
- Date: 20 Mar 1996 09:35:00 -0600
- Organization: Mississippi State University
- Message-ID: <mhp1.827335696@Ra.MsState.Edu>
- References: <Pine.LNX.3.91.960319173746.16221A-100000@larry.inf.net>
- NNTP-Posting-Host: ra.msstate.edu
- X-Newsreader: NN version 6.5.0 #2 (NOV)
-
- Lawrence O'Leary <larry@larry.inf.net> writes:
-
- > What I want to do is create each record in the array by reading a line
- > from a file and storing each field of the line into the record. Do this
- > for every line in the file and then where done. What I need to do is
- > create the array of the struct for the exact number of lines that are in
- > the file. This way I won't be wasting memory and I won't have to worry
- > about not having enough records to store the lines into.
-
- Currently using ISO C this is not possible. In future revisions of C you
- can have dynamically sized arrays like you currently can using GNU'c C
- compiler. However, while you can specify the size at runtime, you must
- still specify a size -- it won't grow dynamically. To do what you want you
- would first have to determine the number of lines in the file, then
- allocate the array, then read in the lines. Of course, you also have to
- use a compiler (like GNU's gcc) that allows dynamic arrays.
-
- Michael
-
- P.S. There are other things you can do using other data structures that
- would still allow quick access to any record.
-